from django.db import models
from datetime import datetime
import random
# Create your models here.
class FormCustomer(models.Model):
    MAX_VALUE = 2147483647
    aike_status_level = ((0, u'否'), (1, u'是'))
    # sem_status_level = ((0, u'否'), (1, u'是'))
    company_name = models.CharField(max_length=255,  verbose_name='公司名', unique=True)
    url = models.CharField(max_length=255, verbose_name='公司域名', null=True, blank=True)
    company_type = models.CharField(max_length=255, verbose_name='公司类型', null=True, blank=True)
    phone = models.TextField(verbose_name='手机号', null=True, blank=True)
    qq = models.CharField(max_length=255, verbose_name='QQ', null=True, blank=True)
    wechat = models.CharField(max_length=255, verbose_name='微信号', null=True, blank=True)
    aike_status = models.IntegerField(verbose_name='爱客系统', default=0, choices=aike_status_level)
    sem_status = models.IntegerField(verbose_name='sem客户', default=0)
    useless_counter = models.IntegerField(verbose_name='无效次数', default=0)
    city = models.CharField(max_length=255, verbose_name='所在城市', null=True, blank=True)
    address = models.TextField(verbose_name='地址', null=True, blank=True)
    create_time = models.DateTimeField(verbose_name='首次发现', default=datetime.now, blank=True)
    update_time = models.DateTimeField(verbose_name='最后更新', blank=True, null=True, default=None)
    remark = models.TextField(verbose_name='备注', blank=True, null=True)
    randid = models.BigIntegerField(db_index=True, verbose_name='随机数', default=random.randint(1, MAX_VALUE))
    keyword = models.CharField(max_length=255, verbose_name='搜索关键词', null=True, blank=True)
    amount = models.IntegerField(verbose_name='签单金额', null=True, blank=True, default=0)
    depart = models.CharField(max_length=255, verbose_name='负责销售部门', null=True, blank=True)
    sales = models.CharField(max_length=255, verbose_name='负责销售人员', null=True, blank=True)
    business = models.IntegerField(verbose_name='商机', default=0)
    level = models.IntegerField(verbose_name='轮换次数', default=0, null=False, blank=False)
    discover_time = models.DateTimeField(verbose_name='最近发现时间', null=True, blank=True)
    discover_count = models.IntegerField(verbose_name='发现次数', default=1, null=False, blank=False)

    class Meta:
        db_table = 'form_customer'
        verbose_name = '公司信息'
        verbose_name_plural = verbose_name
        ordering = ['-create_time']

    def __str__(self):
        return self.company_name
